﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace CrossingSwords
{
    class ChoiceBox
    {
        Texture2D image;
        Vector2 position;
        String text;
        String[] options;
        int select;
        public bool isActive;

        public ChoiceBox(Texture2D img, Vector2 pos, String message, String[] options)
        {
            image = img;
            position = pos;
            text = message;
            this.options = options;
            select = 0;
            isActive = false;
        }

        public void Update(KeyboardState keyboard,KeyboardState control)
        {
            if (keyboard.IsKeyDown(Keys.Down) && !control.IsKeyDown(Keys.Down))
                select++;
            else if (keyboard.IsKeyDown(Keys.Up) && !control.IsKeyDown(Keys.Up))
                select--;
            if (select < 0)
                select = options.Length - 1;
            if (select > options.Length - 1)
                select = 0;
        }

        public void Draw(SpriteBatch render, SpriteFont font)
        {
            render.Draw(image, position, Color.White);
            render.DrawString(font, text, new Vector2(position.X + 5, position.Y + 10), Color.Black);
            for (int i = 0; i < options.Length; i++)
            {
                if(select == i)
                    render.DrawString(font, options[i], new Vector2(position.X + 5, position.Y + 10 + 10 * i)+font.MeasureString(text), Color.Blue);
                else
                    render.DrawString(font, options[i], new Vector2(position.X + 5, position.Y + 20 + 10 * i), Color.Black);
            }
        }
    }
}
